package model

import (
	"gorm.io/gorm"
	"wechat01/handler/response"
)

type User struct {
	gorm.Model
	Phone     string `gorm:"type:char(11)" json:"phone"`
	Password  string `gorm:"type:char(32)" json:"password"`
	NickName  string `gorm:"type:varchar(30)" json:"nickName"`
	AvatarUrl string `gorm:"type:varchar(255)" json:"avatarUrl"`
	Refer     string `gorm:"type:varchar(50)" json:"refer"`
}

func (u *User) IsUser(db *gorm.DB, phone string) error {
	return db.Where("phone = ?", phone).First(&u).Error
}
func (u *User) Register(db *gorm.DB) error {
	return db.Create(&u).Error
}
func (u *User) GetUser(db *gorm.DB, userId int) (list response.SearchList, err error) {
	err = db.Model(&u).Select("phone,nick_name,avatar_url,refer").
		Where("id = ?", userId).First(&list).Error
	return
}
